package com.casic.ops.entity.dto.pipeline.datastructure.event.handler;

import com.casic.ops.entity.dto.pipeline.PushNodeExecuteStatusDTO;
import com.casic.ops.entity.dto.pipeline.datastructure.event.EventHandler;
import com.casic.ops.entity.dto.pipeline.datastructure.event.EventHandlerI;
import com.casic.ops.entity.dto.pipeline.datastructure.event.PipelineNodeRefreshEvent;
import com.casic.ops.entity.vo.pipeline.response.Response;
import com.casic.ops.handler.pipeline.PipelineExecuteSocketService;
import lombok.extern.slf4j.Slf4j;

import javax.annotation.Resource;

/**
 * 流水线节点更新事件处理器
 * @author cww
 * @date 2022/6/17 22:57:10
 */
@Slf4j
@EventHandler
public class PipelineRefreshEventHandler implements EventHandlerI<Response, PipelineNodeRefreshEvent> {

    @Resource
    private PipelineExecuteSocketService pipelineExecuteSocketService;

    public Response execute(PipelineNodeRefreshEvent event) {

//        log.error("Handling Event:{}",event);
//这里用WebSocket实时更新pipeline节点执行状态，返回了一个特定的数据结构，前端要根据这个数据结构来实现流水线的执行动效。
        pipelineExecuteSocketService.sendMessage(event.getUuid(),
                PushNodeExecuteStatusDTO.builder().edges(event.getEdges()).nodes(event.getData()).build());
        //加队列执行

        return Response.success();
    }
}
